// connect 作为store和组件之间的一个桥梁

import {connect} from 'react-redux'
import {ITodo} from '../../store/types'

import { Dispatch } from 'redux'
import { ADD_TODO } from '../../store/action'

let id = 1;

type ToDos = {
    todos: Array<ITodo>
}
const mapStateToProps = (state: ToDos) =>{
    return {
        todos: state.todos
    }
}
const mapDispatchToProps = (dispatch: Dispatch) =>{
    return {
        add: (txt: string)=>{
            dispatch({
                type: ADD_TODO,
                id: id++,
                text: txt
            })
        }
    }
}
export default connect(mapStateToProps, mapDispatchToProps)